package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.ems.pojo.DitDataVO;
import com.econ.powercloud.ems.pojo.EmsCombinationDetailVO;
import com.econ.powercloud.ems.pojo.EmsCombinationVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsCombinationDetailRequestVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsCombinationRequestVO;
import com.econ.powercloud.ems.pojo.requestVO.SingleListRequestVO;
import com.econ.powercloud.ems.service.biz.EmsCombinationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : zjf
 * @Description : 查看实时监控/历史数据的组合controller
 * @Date : 2022/4/18 14:07
 * @Modified by : zjf
 */
@RestController
@Api(tags ="组合查询")
@RequestMapping(value = "/api/v2/combination")
public class EmsCombinationController extends ApiBaseController {

    @Autowired
    private EmsCombinationService emsCombinationService;

    @ApiOperation(value = "获取已保存的组合列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "type", value = "类型，1：实时监控，2：历史数据", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "stationId", value = "储能站id", dataType = "String"),
    })
    @GetMapping("queryCombinationList")
    public MsgResult<List<EmsCombinationVO>> queryCombinationList(@RequestParam(value = "type") Integer type,
                                                                  @RequestParam(value = "stationId") String stationId){
        return successHandler(emsCombinationService.getCombinationListByStationIdAndType(type,stationId));
    }

    @ApiOperation(value = "获取组合的保存数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "combinationId", value = "组合id", dataType = "String"),
    })
    @GetMapping("queryCombinationDetail")
    public MsgResult<List<EmsCombinationDetailVO>> queryCombinationDetail(@RequestParam(value = "combinationId") String combinationId){
        return successHandler(emsCombinationService.getCombinationDetailListByCombinationId(combinationId));
    }

    @ApiOperation(value = "删除组合")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "combinationId", value = "组合id", dataType = "String"),
    })
    @DeleteMapping("deleteCombination")
    public MsgResult<String> deleteCombination(@RequestParam(value = "combinationId") String combinationId){
        return successHandler(emsCombinationService.deleteByCombinationId(combinationId));
    }

    @ApiOperation(value = "新增组合")
    @PostMapping("addCombination")
    public MsgResult<String> addCombination(@RequestBody EmsCombinationRequestVO<EmsCombinationDetailRequestVO> requestVO){
        return successHandler(emsCombinationService.addCombination(requestVO));
    }

    @ApiOperation(value = "修改组合")
    @PutMapping("modifyCombination")
    public MsgResult<String> modifyCombination(@RequestBody EmsCombinationRequestVO<EmsCombinationDetailRequestVO> requestVO){
        return successHandler(emsCombinationService.modifyCombination(requestVO));
    }

    @ApiOperation(value = "新增组合通过点号类型等")
    @PostMapping("addByDitType")
    public MsgResult<String> addByDitType(@RequestBody @Validated EmsCombinationRequestVO<DitDataVO> requestVO){
        return successHandler(emsCombinationService.addCombinationByDitType(requestVO));
    }

    @ApiOperation(value = "修改组合通过点号类型等")
    @PutMapping("modifyByDitType")
    public MsgResult<String> modifyByDitType(@RequestBody EmsCombinationRequestVO<DitDataVO> requestVO){
        return successHandler(emsCombinationService.modifyCombinationByDitType(requestVO));
    }

}
